/********************************************************************************
 * Project Name		[JavaEE_Web]
 * File Name     	[AttributeIn4ScopesServlet.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package jsp;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * JSP作用域的四个对象
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
@WebServlet(name = "AttributeIn4ScopesServlet", urlPatterns = "/attrInScope")
public class AttributeIn4ScopesServlet extends HttpServlet {

	private static final long serialVersionUID = 3850004922546343667L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获得page作用域的属性[无法得到]

		// 获得request作用域的属性
		String requestAttr = (String) request.getAttribute("requestAttrName");
		System.out.println(requestAttr);

		// 获得session作用域的属性
		String sessionAttr = (String) request.getSession().getAttribute("sessionAttrName");
		System.out.println(sessionAttr);

		// 获得application作用域的属性
		String applicationAttr = (String) request.getServletContext().getAttribute("applicationAttrName");
		System.out.println(applicationAttr);
	}
}
